package main.java.com.lee.atomic;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.LongAdder;
import java.util.stream.IntStream;

/**
 * @Description TODO
 * @Author winston
 * @DateTime 2021/12/28
 */
public class LongAdderTest {

    static LongAdder adder = new LongAdder();
    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        ExecutorService exe = Executors.newFixedThreadPool(10);
        IntStream.rangeClosed(1, 10).forEach(i->{
            exe.submit(LongAdderTest::selfPlus);
        });
        exe.shutdown();
        while (!exe.isTerminated()) {
            System.out.println("轮询关闭");
        }
        System.out.println(adder.intValue());
        long end = System.currentTimeMillis() - start;
        System.out.println(end);
    }

    private static void selfPlus() {
        IntStream.rangeClosed(1, 10000000).forEach(i->{
            adder.add(1);
        });
    }
}
